Warning: package 'sf' was built under R version 4.2.3
Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(ggplot2)
Warning: package 'ggplot2' was built under R version 4.2.3
library(dplyr)
Warning: package 'dplyr' was built under R version 4.2.3
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(spdep)
Warning: package 'spdep' was built under R version 4.2.3
Loading required package: spData
To access larger datasets in this package, install the spDataLarge
package with: `install.packages('spDataLarge',
repos='https://nowosad.github.io/drat/', type='source')`
library(tmap)
Breaking News: tmap 3.x is retiring. Please test v4, e.g. with
remotes::install_github('r-tmap/tmap')
library(leaflet)
Warning: package 'leaflet' was built under R version 4.2.3
date province_thai province_eng region_thai region_eng
1 2019-01-01 กรุงเทพมหานคร Bangkok ภาคกลาง central
2 2019-01-01 ลพบุรี Lopburi ภาคกลาง central
3 2019-01-01 พระนครศรีอยุธยา Phra Nakhon Si Ayutthaya ภาคกลาง central
4 2019-01-01 สระบุรี Saraburi ภาคกลาง central
5 2019-01-01 ชัยนาท Chainat ภาคกลาง central
6 2019-01-01 นครปฐม Nakhon Pathom ภาคกลาง central
variable value
1 ratio_tourist_stay 93.37
2 ratio_tourist_stay 61.32
3 ratio_tourist_stay 73.37
4 ratio_tourist_stay 67.33
5 ratio_tourist_stay 79.31
6 ratio_tourist_stay 71.70
Data Preparation
We will merge the tourism data with the province-level shapefile using the province names in English.
The current dataset uses the first day of each month to represent the date, so we will extract the year and month to perform the analysis.
# Convert the 'date' column to Date format if it's not alreadytourism_df$date <-as.Date(tourism_df$date, format ="%Y-%m-%d")# Extract year and month from the datetourism_df$year <-format(tourism_df$date, "%Y")tourism_df$month <-format(tourism_df$date, "%m")# Merge the datasets on province namemerged_data <-merge(gdf1, tourism_df, by.x ="ADM1_EN", by.y ="province_eng")# Display the first few rows of the merged datahead(merged_data)
We will visualize the distribution of tourist arrivals across provinces using an interactive map.
merged_data_simplified <-ms_simplify(merged_data, keep =0.05) # Create a choropleth map to visualize tourist arrivals across provincestmap_mode("view") # Interactive map mode
tmap mode set to interactive viewing
tm_shape(merged_data_simplified) +tm_polygons("value", palette ="OrRd", title ="Tourist Arrivals (2019-2023)") +tm_layout(title ="Tourist Arrivals by Province in Thailand")